{template 'header'}

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">发圈任务审核</a>
        <a>
          <cite>发圈任务提交列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="userinfo" value="{$userinfo}" placeholder="手机号/真实姓名" autocomplete="off"
                   class="layui-input">
            <input class="layui-input" placeholder="提交开始时间" name="start_time_2" id="start_time_2"
                   value="{$_GPC['start_time_2']}">
            <input class="layui-input" placeholder="提交结束时间" name="end_time_2" id="end_time_2"
                   value="{$_GPC['end_time_2']}">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="reviewAll(1)">
            <i class="layui-icon">&#xe6af;</i>批量通过
        </button>
        <button class="layui-btn" onclick="reviewAll(0)">
            <i class="layui-icon">&#xe69c;</i>批量驳回
        </button>
        <span class="x-right" style="line-height:40px">共有数据：{$total} 条</span>
    </xblock>
    <table class="layui-table x-admin">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>编号</th>
            <th>提交人</th>
            <th>提交时间</th>
            <th>图片依据</th>
            <th>审核状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {if $total==0}

        <tr>
            <td colspan="11" style="text-align: center;">暂无数据</td>
        </tr>

        {else}
        {loop $list $item}
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$item["id"]}'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$item['id']}</td>
            <td>{if !empty($item['truename'])}{$item['truename']}:{/if}用户ID:{$item['user_id']}<br>手机号:{$item['mobile']}</td>
            <td>{php echo date('Y-m-d H:i:s',$item['create_time'])}</td>
            <td>
                <button class="layui-btn layui-btn-warm" onclick="preview_thumb('{$item['submit_img']}')">
                    查看图片
                </button>
            </td>
            <td>
                {if $item['receive_status']==2 && $item['review_status']==0}待审核
                {elseif $item['review_status']==1}已通过
                {elseif $item['review_status']==2}已驳回
                {else}任务未完成
                {/if}
            </td>
            <td class="td-manage">
                <a title="通过" onclick="review(this,{$item['id']},1)" href="javascript:;">
                    <i class="layui-icon">&#xe6af;</i>
                </a>
                <a title="驳回" onclick="review(this,{$item['id']},0)" href="javascript:;">
                    <i class="layui-icon">&#xe69c;</i>
                </a>
            </td>
        </tr>
        {/loop}
        {/if}
        </tbody>
    </table>
    <div class="page">
        {$pager}
    </div>

</div>
<script>
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(sreach)', function (data) {
            console.log(data.field)
            var str = '';
            for (var key in data.field) {
                str += key + "=" + data.field[key] + "&";
            }
            var url = '{php echo $this->createWebUrl("share_task_log_review")}'
            location.href = url + "&" + str;
            return false;
        });
    });
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start_time_2', //指定元素
            type: 'datetime'
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end_time_2', //指定元素
            type: 'datetime'
        });
    });
</script>
<script>
    String.prototype.trim = function (char, type) {
        if (char) {
            if (type == 'left') {
                return this.replace(new RegExp('^\\' + char + '+', 'g'), '');
            } else if (type == 'right') {
                return this.replace(new RegExp('\\' + char + '+$', 'g'), '');
            }
            return this.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), '');
        }
        return this.replace(/^\s+|\s+$/g, '');
    };
</script>
<script>
    function preview_thumb(thumbs) {
        var json = [];
        if (thumbs == '') json = [];
        thumbs = thumbs.trim(';')
        var arr = thumbs.split(';')
        for (var i = 0; i < arr.length; i++) {
            var item = {};
            item.src = arr[i];
            json.push(item)
        }
        layer.photos({
            photos: {
                "data": json
            }
        });
    }
</script>
<script>
    function review(obj,id, yes) {
        var data = {id, yes}
        if (yes == 0) {
            layer.prompt({title: '请填写理由，并确认', formType: 2}, function(text, index){
                layer.close(index);
                data.review_mark = text
                var url = '{php echo $this->createWebUrl("share_task_log_review",["op"=>"review"])}'
                $.post(url, data, function (ret) {
                    if (ret.code) {
                        $(obj).parents("tr").remove();
                    } else {
                        layer.msg(ret.msg, {icon: 0});
                    }
                }, 'json')
            });
        }else{
            var url = '{php echo $this->createWebUrl("share_task_log_review",["op"=>"review"])}'
            $.post(url, data, function (ret) {
                if (ret.code) {
                    layer.msg(ret.msg, {icon: 1, time: 1000});
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        }
    }

    function reviewAll(yes) {
        var ids = tableCheck.getData();
        var data = {ids, yes}
        if (yes == 0) {
            layer.prompt({title: '请填写理由，并确认', formType: 2}, function(text, index){
                layer.close(index);
                data.review_mark = text
                var url = '{php echo $this->createWebUrl("share_task_log_review",["op"=>"review"])}'
                $.post(url, data, function (ret) {
                    if (ret.code) {
                        layer.msg(ret.msg, {icon: 1, time: 1000});
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    } else {
                        layer.msg(ret.msg, {icon: 0});
                    }
                }, 'json')
            });
        }else{
            var url = '{php echo $this->createWebUrl("share_task_log_review",["op"=>"review"])}'
            $.post(url, data, function (ret) {
                if (ret.code) {
                    layer.msg(ret.msg, {icon: 1, time: 1000});
                    $(".layui-form-checked").not('.header').parents('tr').remove();
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        }
    }
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>